package com.hanfengyi.web.controller;

import com.hanfengyi.course.domain.CourseType;
import com.hanfengyi.course.temp.CourseNativeSearchQueryBuilder;
import com.hanfengyi.doc.CourseDoc;
import com.hanfengyi.doc.CourseDocRepository;
import com.hanfengyi.hrm.AjaxResult;
import com.hanfengyi.hrm.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * User: Han
 * Date: 2020/2/23
 * Time: 16:04
 * Description:
 */
@RestController
@RequestMapping("/es")
public class EScontroller {
    @Autowired
    private CourseDocRepository courseDocRepository;
    @GetMapping("/get/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        courseDocRepository.deleteById(id);
        return AjaxResult.me();
    }
    @PostMapping("/save")
    public AjaxResult save(@RequestBody CourseDoc courseDoc){
        courseDocRepository.save(courseDoc);
        return AjaxResult.me();
    }

    @PostMapping("/searchByQuery")
    PageList<CourseType> searchByQuery(@RequestBody CourseNativeSearchQueryBuilder courseNativeSearchQueryBuilder){
        Page<CourseDoc> search = courseDocRepository.search(courseNativeSearchQueryBuilder.build());
        PageList pageList = new PageList(search.getTotalElements(), search.getContent());
        return pageList;
    }
}